/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queryterm;

/**
 *
 * @author Zakiy Firdaus
 */
public class QueryTerm {
    public QueryTerm(){
        
    }
    
    private String token;
    private float weight;
    private int field;
    private boolean oneword;
    // Jenis field yang ada
    public static final int All_FIELD = 0;
    public static final int FROM_FIELD = 1;
    public static final int TO_FIELD = 2;
    public static final int SUBJECT_FIELD = 3;
    public static final int DATE_FIELD = 4;
    public static final int BODY_FIELD = 5;
    
    public QueryTerm(String t, float w, int f, boolean b){
        token = t;
        weight = w;
        field = f;
        oneword = b;
    }
    
    public void setToken(String t){
        token = t;
    }
    
    public void setWeight(float w){
        weight = w;
    }
    
    public void setField(int f){
        field = f;
    }
    
    public void setOneWord(boolean b){
        oneword = b;
    }
    
    public String getToken(){
        return token;
    }
    
    public float getWeight(){
        return weight;
    }
    
    public int getField(){
        return field;
    }
    
    public boolean getIsOneWord(){
        return oneword;
    }
    
    public String getFieldString(){
        switch (field) {
            case All_FIELD:  return "all";
            case FROM_FIELD:  return "from";
            case TO_FIELD:  return "to";
            case SUBJECT_FIELD:  return "subject";
            case DATE_FIELD:  return "date";
            case BODY_FIELD:  return "body";
        }
        return "";
    }
    
    public static String getFieldString(int f){
        switch (f) {
            case All_FIELD:  return "all";
            case FROM_FIELD:  return "from";
            case TO_FIELD:  return "to";
            case SUBJECT_FIELD:  return "subject";
            case DATE_FIELD:  return "date";
            case BODY_FIELD:  return "body";
        }
        return "";
    }
    
    public static int getFieldInt(String s){
        if(s.equals("from")){
            return FROM_FIELD;
        } else if(s.equals("to")){
            return TO_FIELD;
        } else if(s.equals("subject")){
            return SUBJECT_FIELD;
        } else if(s.equals("date")){
            return DATE_FIELD;
        } else if(s.equals("body")){
            return BODY_FIELD;
        }
        return All_FIELD;
    }
}
